#include "outcdialog.h"
#include "ui_outcdialog.h"

outcDialog::outcDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::outcDialog)
{
    ui->setupUi(this);
    this->setWindowTitle("外来人员登记信息查询");
    ui->tableWidget->clear();
    ui->tableWidget->setColumnCount(5);
    ui->tableWidget->setHorizontalHeaderLabels(QStringList()<<"宿舍楼号"<<"姓名"<<"联系电话"<<"登记时间"<<"身份证号");
    ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);//禁止删改
    ui->tableWidget->setSelectionMode(QTableWidget::SingleSelection);
    ui->tableWidget->verticalHeader()->setVisible(false);
    ui->tableWidget->setColumnWidth(0,75);
    ui->tableWidget->setColumnWidth(1,75);
    ui->tableWidget->setColumnWidth(2,100);
    ui->tableWidget->setColumnWidth(3,100);
    ui->tableWidget->horizontalHeader()->setSectionResizeMode(4,QHeaderView::Stretch);
    QFont font=ui->tableWidget->horizontalHeader()->font();
    font.setBold(true);
    ui->tableWidget->horizontalHeader()->setFont(font);
}

outcDialog::~outcDialog()
{
    delete ui;
}

void outcDialog::on_pushButton_clicked()
{
    OutDialog *w=new OutDialog;
    this->hide();
    w->show();
}

void outcDialog::on_pushButton_2_clicked()
{

    QString fileName="C:\\Users\\Administrator\\Desktop\\QT\\jilu.txt";
    int r_count=0;
    QStringList textlist;
    bool sign=w.inqOut(fileName,textlist,r_count);     //函数调用
           if(sign){
               if(!textlist.isEmpty()&&r_count>1){
                   QStringList ListColHeader=textlist.at(1).split(",");
                   QStringList listRowHeader=textlist.at(0).split(",");
                   int c_count=listRowHeader.count();
                   ui->tableWidget->clear();
                   ui->tableWidget->setRowCount(r_count-1);
                   ui->tableWidget->setColumnCount(c_count-1);//给表格设置行数和列数
                   ui->tableWidget->setHorizontalHeaderLabels(listRowHeader);
                   ui->tableWidget->setVerticalHeaderLabels(ListColHeader);//设置表头
                   for(int row=0;row<r_count;row++){
                       QStringList tmpList;
                       tmpList=textlist.at(row).split(",");
                       for(int col=0;col<c_count;col++){
                           QTableWidgetItem *item=new QTableWidgetItem(tmpList.at(col));
                           ui->tableWidget->setItem(row-1,col,item);//设置行
                       }//呈现入表格
                   }
               }else{
                   QMessageBox::information(0,tr("提示"),tr("文件数据为空!"));
               }
           
        }else{
              QMessageBox::warning(0,tr("警告"),tr("文件名未指定"),QMessageBox::Ok);
        }
      
}
